import {
    TreeViewActionType,
    ITreeViewAbility,
    ITreeViewController,
    ITreeViewControllerParams,
    ITreeViewModel,
    ITreeViewStore,
    IParam,
    IViewEvent,
} from '@/core';
import { QXEvent } from 'qx-util';
import {
    getViewClassNames,
    handleQuickGroupValueChange,
    useViewAction,
    useViewBasic,
    useViewControllerParams,
    useViewProps,
} from '../use-view';

/**
 * 获取树视图输入参数
 *
 * @export
 * @return {*}
 */
export function useTreeViewProps() {
    return {
        ...useViewProps(),
    };
}

/**
 * 获取树视图基础
 *
 * @export
 * @param {ITreeViewModel} model 树视图模型
 * @param {IParam} props 输入参数
 * @return {*}
 */
export function useTreeViewBasic(model: ITreeViewModel, props: IParam) {
    const getSearchFormSlotName = (props: IParam) => {
        const showTabPageExp = App.getProjectSetting().multiTabsSetting.show;
        let searchFormSlotName = 'viewHeaderTop';
        if (!showTabPageExp && props.openType == 'ROUTE') {
            searchFormSlotName = 'viewHeaderBottom';
        }
        return searchFormSlotName;
    }
    const getClassNames = (props: IParam) => {
        return getViewClassNames(model, props)
    }
    return {
        ...useViewBasic(model, props),
        getClassNames,
        getSearchFormSlotName,
        handleQuickGroupValueChange,
    };
}

/**
 * 树视图行为
 *
 * @export
 */
export function useTreeViewAction(controller: ITreeViewController<ITreeViewStore, ITreeViewAbility>) {
    return {
        ...useViewAction(controller)
    };
}

/**
 * 获取树视图控制器输入参数
 *
 * @export
 * @param {ITreeViewModel} model
 * @param {IParam} props
 * @param {QXEvent<IViewEvent<TreeViewActionType, ITreeViewAbility>>} evt
 * @return {*}  {ITreeViewControllerParams<TreeViewActionType, ITreeViewAbility>}
 */
export function useTreeViewControllerParams(
    model: ITreeViewModel,
    props: IParam,
    evt: QXEvent<IViewEvent<TreeViewActionType, ITreeViewAbility>>
): ITreeViewControllerParams<TreeViewActionType, ITreeViewAbility> {
    return {
        ...useViewControllerParams<ITreeViewStore, ITreeViewModel>(
            model,
            props,
            evt
        ),
    };
}
